<!--
 * @FileDescription: 使用 CSS Scroll Snap 优化滚动，提升用户体验！
 * @Author: wangzhichiao<https://github.com/wzc570738205>
 * @Date: 2021-09-17 13:42:02
 * @LastEditors: wangzhichiao<https://github.com/wzc570738205>
 * @LastEditTime: 2021-09-17 13:42:02
-->
<template>
  <div class="section">
    <div class="section__item bg-1">Item 1</div>
    <div class="section__item bg-2">Item 2</div>
    <div class="section__item bg-3">Item 3</div>
    <div class="section__item bg-4">Item 4</div>
    <div class="section__item bg-5">Item 5</div>
  </div>
</template>

<script>
export default {
};
</script>

<style scoped>
.section {
  display: flex;
  gap: 20px;
  max-width: 450px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  box-shadow: 0 3px 10px 0 rgba(#000, 0.1);
  -webkit-overflow-scrolling: touch;
  scroll-padding: 1rem;
  padding: 1rem;
  margin: 3rem auto 0;
  border-radius: 5px;
}

.section__item {
  display: flex;
  justify-content: center;
  align-items: center;
  flex: 0 0 300px;
  width: 30px;
  height: 150px;
  scroll-snap-align: start;
  background-color: #ccc;
  font-size: 1.5rem;
}

/* Other styles */

body {
  font-family: "Arial";
  padding: 1rem;
  background-color: #f7f7f7;
}

.bg-1 {
  background-color: #f1c2c6;
}

.bg-2 {
  background-color: #dac2f1;
}

.bg-3 {
  background-color: #ccf1c2;
}

.bg-4 {
  background-color: #c2e9f1;
}

.bg-5 {
  background-color: #f1ebc2;
}
</style>
